package io.hepu.robotize.util;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public final class Joins {
    static final String DELIMITER = ":";
    static final String COMMA = ",";

    private Joins() {}

    public static String join(String delimiter, Object... elements) {
        Objects.requireNonNull(delimiter);
        Objects.requireNonNull(elements);
        return Arrays.stream(elements).map(Object::toString).collect(Collectors.joining(delimiter));
    }

    public static Integer[] join(String delimiter, Integer... elements) {
        Objects.requireNonNull(delimiter);
        Objects.requireNonNull(elements);
        return Arrays.stream(elements).toArray(Integer[]::new);
    }

    public static Long[] join(String delimiter, Long... elements) {
        Objects.requireNonNull(delimiter);
        Objects.requireNonNull(elements);
        return Arrays.stream(elements).toArray(Long[]::new);
    }

    public static Double[] join(String delimiter, Double... elements) {
        Objects.requireNonNull(delimiter);
        Objects.requireNonNull(elements);
        // Arrays.copyOfRange(elements, 0, elements.length, Double[].class);
        return Arrays.stream(elements).toArray(Double[]::new);
    }

    public static String join(String delimiter, String... elements) {
        Objects.requireNonNull(delimiter);
        Objects.requireNonNull(elements);
        return String.join(delimiter, elements);
    }

    public static String join(List<?> elements) {
        Objects.requireNonNull(elements);
        return elements.stream().map(Object::toString).collect(Collectors.joining(COMMA));
    }

    public static String join(String delimiter, List<?> elements) {
        Objects.requireNonNull(delimiter);
        Objects.requireNonNull(elements);
        return elements.stream().map(Object::toString).collect(Collectors.joining(delimiter));
    }

    public static String concat(Object... elements) {
        return concat(DELIMITER, elements);
    }

    public static String concat(String delimiter, Object... elements) {
        return Arrays.stream(elements).map(Object::toString).collect(Collectors.joining(delimiter));
    }
}
